/*
 * 入职 离职
 */
var url = '', jsonData = '';
$(function(){
	loadData();
});

function loadData(){
	loadTopCSS();
	/**
	 * 入职/离职 人数/比率 柱状图  折线图
	 */
	loadEntryAndLeavePeople();
	 
}

function loadTopCSS() {
	$("#li3").addClass("navdown");
}

/*
 * 入职率、离职率
 */
function loadEntryAndLeavePeople() {
	url = ctx + '/entryLeaveController/entryLeave';
	var departmentId = $('#departmentId').val();
	var startTime = $('#startEntryAndLeaveOffice').val();
	var endTime = $('#endEntryAndLeaveOffice').val();
	console.log("startTime"+startTime);
	if (startTime.length==0||endTime.length==0||startTime==endTime) {
		
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		
		var startYear = year-1;
		
		startTime = startYear+"-"+month;
		endTime = year+"-"+month;
		
	}
	
	$('#startEntryAndLeaveOffice').val(startTime);
	$('#endEntryAndLeaveOffice').val(endTime);
	
	
	jsonData = {departmentId:departmentId,startTime:startTime,endTime:endTime};
	var  returnData= commonAjax();
	initStackBarChart(returnData.title,returnData.data,returnData.dates,returnData.name1,returnData.name2,document.getElementById('entryAndLeavePeopleMain'));
	
}

function commonAjax(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}
/**
 *  ！！！！！！！！！！！异步请求！！！！！！！！！！！！！
 */
/*function commonAjax(fun, dataType){
	$.ajax({
		type: 'POST',
		data: jsonData,
	    url: url,
	    dataType: dataType,
	    success: function(data){
	    	fun(data);
	    },
	    error: function(){
	    }
	});
}*/